﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using deckAnalyser.Support;

namespace deckAnalyser.Domain
{
  public class Collection : DomainObject
  {
    private String name;
    public String Name
    {
      get { return name; }
      set { name = value; IsDirty = true; NotifyListeners(); }
    }

    private String decription;
    public String Description
    {
      get { return decription; }
      set { decription = value; IsDirty = true; NotifyListeners(); }
    }

    public override string Caption
    {
      get { return Name; }
    }

    public Collection(String name)
    {
      Name = name;

      String result = DBWrapper.ExecuteScalar(
        "SELECT count(*) FROM collections.collections c WHERE name='" + Name + "'"
      );

      if (Int32.Parse(result) == 0)
        DBWrapper.ExecuteNonQuery(
          " INSERT INTO collections.collections (name,description)" +
          " VALUES ('" + Name + "','" + Description + "')"
        );
    }
  }
}
